﻿using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Effects;

namespace Black.SurfaceToolkit.Effects
{
    /// <summary>
    /// ContrastAdjustEffect Effect
    /// </summary>
    public class ContrastAdjustEffect : ShaderEffect
    {
        #region Propriétées de dépendances

        public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(ContrastAdjustEffect), 0);
        public static readonly DependencyProperty BrightnessProperty = DependencyProperty.Register("Brightness", typeof(double), typeof(ContrastAdjustEffect), new UIPropertyMetadata(0.0, ShaderEffect.PixelShaderConstantCallback(0)));
        public static readonly DependencyProperty ContrastProperty = DependencyProperty.Register("Contrast", typeof(double), typeof(ContrastAdjustEffect), new UIPropertyMetadata(1.0, ShaderEffect.PixelShaderConstantCallback(1)));

        #endregion

        #region Accesseurs

        /// <summary>
        /// Affecte ou retourne la propriété Input du Shader
        /// </summary>
        [System.ComponentModel.BrowsableAttribute(false)]
        public Brush Input
        {
            get
            {
                return ((Brush)this.GetValue(ContrastAdjustEffect.InputProperty));
            }
            set
            {
                this.SetValue(ContrastAdjustEffect.InputProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété Brightness du Shader
        /// </summary>
        public double Brightness
        {
            get
            {
                return ((double)this.GetValue(ContrastAdjustEffect.BrightnessProperty));
            }
            set
            {
                this.SetValue(ContrastAdjustEffect.BrightnessProperty, value);
            }
        }

        /// <summary>
        /// Affecte ou retourne la propriété Contrast du Shader
        /// </summary>
        public double Contrast
        {
            get
            {
                return ((double)this.GetValue(ContrastAdjustEffect.ContrastProperty));
            }
            set
            {
                this.SetValue(ContrastAdjustEffect.ContrastProperty, value);
            }
        }

        #endregion

        #region Variables statiques

        private static readonly PixelShader _PixelShader = new PixelShader();

        #endregion

        #region Constructeurs

        /// <summary>
        /// Constructeur statique
        /// </summary>
        static ContrastAdjustEffect()
        {
            ContrastAdjustEffect._PixelShader.UriSource = new Uri("pack://application:,,,/Black.SurfaceToolkit;component/Effects/Shaders/ContrastAdjust.ps");
        }

        /// <summary>
        /// Constructeur de la classe
        /// </summary>
        public ContrastAdjustEffect()
        {
            this.PixelShader = ContrastAdjustEffect._PixelShader;

            this.UpdateShaderValue(ContrastAdjustEffect.InputProperty);
            this.UpdateShaderValue(ContrastAdjustEffect.BrightnessProperty);
            this.UpdateShaderValue(ContrastAdjustEffect.ContrastProperty);
        }

        #endregion
    }
}
